<template>
	<div class="edit-danger">
		<van-field
			class="input_text"
			name="calendar"
			v-model="DName"
			label="隐患分类"
			placeholder="请选择"
			required
			readonly
			@click="goMannerItem"
		>
			<template #right-icon><van-icon name="arrow" /></template>
		</van-field>
		<van-field
			label="依据来源"
			rows="3"
			autosize
			type="textarea"
			v-model="data.GistSource"
			required
		>
		</van-field>
		<van-field
			label="常见隐患"
			rows="3"
			autosize
			type="textarea"
			v-model="data.HiddenDangerDesc"
			required
		>
		</van-field>
		<van-field
			label="整改建议"
			rows="3"
			autosize
			type="textarea"
			v-model="data.CorrectiveAdvise"
			required
		>
		</van-field>
		<van-field
			label="法律原文"
			rows="3"
			autosize
			type="textarea"
			v-model="data.OriginalText"
		>
		</van-field>
		<van-field
			label="法律责任"
			rows="3"
			autosize
			type="textarea"
			v-model="data.LegalLiability"
		>
		</van-field>
		<van-field
			label="关键词"
			rows="3"
			autosize
			type="textarea"
			v-model="data.Keyword"
		>
		</van-field>
		<van-field label="序号" v-model="data.Order"> </van-field>
		<div class="btn_submit">
			<van-button block type="primary" :loading="loading" @click="_submit">
				保存
			</van-button>
		</div>
	</div>
</template>

<script>
import { Add } from '@/api/sytech/sytechDangerLawGist'

export default {
	components: {},
	data() {
		return {
			data: {
				DCode: '',
				GistSource: '',
				HiddenDangerDesc: '',
				CorrectiveAdvise: '',
				OriginalText: '',
				LegalLiability: '',
				Keyword: '',
				Order: '',
			},
			loading: false,
			DName: '',
		}
	},
	created() {},
	activated() {
		if (this.$route.params.typeList) {
			// console.log(this.$route.params,'this.$route.params.typeList');
			this.data.DCode = this.$route.params.typeList.DCode
			this.DName = this.$route.params.typeList.DName
		}
	},
	beforeRouteLeave(to, from, next) {
		if (to.name == 'Classifys') {
			this.data = {}
			this.DName = ''
		}
		next() //继续下一步
	},
	methods: {
		// 保存
		_submit() {
			if (!this.data.DCode) {
				this.$toast('请选择隐患分类')
				return
			}
			if (!this.data.GistSource) {
				this.$toast('请输入依据来源')
				return
			}
			if (!this.data.HiddenDangerDesc) {
				this.$toast('请输入常见隐患')
				return
			}
			if (!this.data.CorrectiveAdvise) {
				this.$toast('请输入整改建议')
				return
			}
			this.loading = true
			Add(this.data).then((res) => {
				this.loading = false
				this.$toast('保存成功')
				setTimeout(() => {
					this.$router.push('/SytechDanger/Classifys')
				}, 500)
			})
		},

		// 跳转选择项
		goMannerItem() {
			// this.$router.push('/SytechDanger/LgdType')
			this.$router.push({
				name: 'LgdType',
				params: {
					path: 'EditDanger',
				},
			})
		},
	},
}
</script>

<style lang="less" scoped>
.edit-danger {
	min-height: 100vh;
	background-color: #e8f1f8;
}
.col-detail {
	color: #333;
	display: flex;
	align-items: center;
	justify-content: space-between;

	.col-del {
		display: flex;
		align-items: center;
		img {
			width: 15px;
			height: 15px;
			margin-right: 5px;
		}
	}
}
.valueclass {
	color: rgb(0, 195, 224);
}
</style>
